set more off
clear
cd "D:\Projects\HeterogeneousExternalities\"

import excel "Output\SimulationResults_Tax_1.5.xlsx", clear

ren A tax_change
ren B fulltax
ren C vmt_opt
ren D opt_rev
ren E s_rev
ren F statetax
gen id=_n
merge 1:1 id using  "Data\AncillarySimulation.dta", nogen keep(3)

*Reverse scaling from Matlab
replace vmt_opt=vmt_opt*10000
tostring county_fips,replace
replace county_fips="0"+county_fips if length(county_fips)==4
merge 1:1 county_fips using "Data\PovertyCounty.dta",keep(3) nogen

gen tb_opt=fulltax*(vmt_opt/24.1022)
gen tb_s=statetax*(vmt/24.1022)

egen total_burden=total(tb_opt)
egen total_burden_verify=total(tb_s)

gen tax_burden_share_opt=tb_opt/total_burden
gen tax_burden_share_s=tb_s/total_burden

sum total_burden

gen opt_gallons=vmt_opt/24.1022
gen opt_tax_burden=opt_gallons*fulltax
gen opt_percap=365*opt_tax_burden/county_pop
	
gen s_gallons=vmt/24.1022
gen s_tax_burden=s_gallons*statetax
gen s_percap=365*s_tax_burden/county_pop

	destring allagesinpovertypercent,replace 
	twoway scatter s_percap allagesinpovertypercent, mlcolor(15) mlwidth(vthin) msymbol(o) msize(medium) mstyle(p6) mcolor(%20)  /*
*/|| scatter opt_percap allagesinpovertypercent, /*
*/ mstyle(p7) mcolor(%20) msymbol(d) msize(medium) legend(label(1 "State Regime") /*
*/label(2 "County Regime") label(3 "") label(4 "") pos(11) order(2 1 4 3) col(2)) xtitle("% of Population in Poverty") ytitle("Tax Burden Per Capita ($'s)")/*
*/legend(size(medium) ring(0) pos(2) textfirst) scale(1) ylabel(0(250)1250,nogrid) xlabel(,nogrid) mlwidth(vthin) mlcolor(p3) /*
*/ || lfit s_percap allagesinpovertypercent, lstyle(p6) lpattern(dash) ||  lfit opt_percap allagesinpovertypercent, lstyle(p7) lpattern(solid) 
	
gen fips=substr(county_fips,1,2)

reghdfe s_percap allagesinpovertypercent  , vce(robust) noabsorb
outreg2 using "Output\TaxBurdens.tex", replace  dec(3) addtext(Urbanization FE, No, State FE, No)


reghdfe s_percap allagesinpovertypercent  , vce(robust) absorb(fips)
outreg2 using "Output\TaxBurdens.tex", append  dec(3) addtext(Urbanization FE, No, State FE, Yes)


reghdfe opt_percap allagesinpovertypercent  ,vce(robust) noabsorb
outreg2 using "Output\TaxBurdens.tex", append  dec(3) addtext(Urbanization FE, No, State FE, No)

reghdfe opt_percap allagesinpovertypercent  ,vce(robust) absorb(fips)
outreg2 using "Output\TaxBurdens.tex", append  dec(3) addtext(Urbanization FE, No, State FE, Yes)



